package o;

import com.huawei.hms.framework.network.restclient.hwhttp.HttpContants;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.io.IOException;
import java.util.List;
import o.fuo.d;
import o.fus.a;

public final class fvq implements fuo {
    private final fue ˎ;

    public fvq(fue o_fue) {
        this.ˎ = o_fue;
    }

    public fvb ˎ(d dVar) throws IOException {
        boolean z = false;
        fus ˊ = dVar.ˊ();
        a ʽ = ˊ.ʽ();
        fuw ˎ = ˊ.ˎ();
        if (ˎ != null) {
            fup contentType = ˎ.contentType();
            if (contentType != null) {
                ʽ.ॱ(HttpContants.KEY_CONTENT_TYPE, contentType.toString());
            }
            long contentLength = ˎ.contentLength();
            if (contentLength != -1) {
                ʽ.ॱ("Content-Length", Long.toString(contentLength));
                ʽ.ˏ("Transfer-Encoding");
            } else {
                ʽ.ॱ("Transfer-Encoding", "chunked");
                ʽ.ˏ("Content-Length");
            }
        }
        if (ˊ.ˋ("Host") == null) {
            ʽ.ॱ("Host", fvg.ॱ(ˊ.ˏ(), false));
        }
        if (ˊ.ˋ("Connection") == null) {
            ʽ.ॱ("Connection", "Keep-Alive");
        }
        if (ˊ.ˋ("Accept-Encoding") == null && ˊ.ˋ("Range") == null) {
            z = true;
            ʽ.ॱ("Accept-Encoding", "gzip");
        }
        List ॱ = this.ˎ.ॱ(ˊ.ˏ());
        if (!ॱ.isEmpty()) {
            ʽ.ॱ(HwAccountConstants.EXTRA_COOKIE, ˏ(ॱ));
        }
        if (ˊ.ˋ("User-Agent") == null) {
            ʽ.ॱ("User-Agent", fvc.ˋ());
        }
        fvb ॱ2 = dVar.ॱ(ʽ.ॱ());
        fvr.ॱ(this.ˎ, ˊ.ˏ(), ॱ2.ʼ());
        fvb.d ˎ2 = ॱ2.ʽ().ˎ(ˊ);
        if (z && "gzip".equalsIgnoreCase(ॱ2.ˋ("Content-Encoding")) && fvr.ˊ(ॱ2)) {
            fxw o_fxo = new fxo(ॱ2.ᐝ().ˋ());
            ˎ2.ॱ(ॱ2.ʼ().ˎ().ˎ("Content-Encoding").ˎ("Content-Length").ˊ());
            ˎ2.ॱ(new fvx(ॱ2.ˋ(HttpContants.KEY_CONTENT_TYPE), -1, fxr.ˎ(o_fxo)));
        }
        return ˎ2.ˏ();
    }

    private String ˏ(List<fug> list) {
        StringBuilder stringBuilder = new StringBuilder();
        int size = list.size();
        for (int i = 0; i < size; i++) {
            if (i > 0) {
                stringBuilder.append("; ");
            }
            fug o_fug = (fug) list.get(i);
            stringBuilder.append(o_fug.ˏ()).append('=').append(o_fug.ˊ());
        }
        return stringBuilder.toString();
    }
}
